package com.metacube.questionbank.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.metacube.questionbank.dao.UserDAO;
import com.metacube.questionbank.dto.UserDTO;
import com.metacube.questionbank.service.Validator;

@Controller
@RequestMapping("/register")	//url pattern
public class RegisterController {
	
	@Autowired
	Validator validate;
	
	@Autowired
	UserDAO userDAO;
	@RequestMapping(value = "/userRegister",  method = RequestMethod.POST)
	public String userRegistration(@ModelAttribute UserDTO userDTO) {
		System.out.println("email : "+userDTO.geteMail());
		if(validate.checkUserData(userDTO)) {
			
			userDAO.insertUserData(userDTO);
			
			return "index.jsp";
			
		} else {
			
			return "index.jsp";
		}	
	}
}
